package com.android.aishangauction.activity.mine;

import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.android.aishangauction.R;
import com.android.aishangauction.model.data;
import com.android.aishangauction.model.dataCallback;
import com.android.aishangauction.model.member.DataEditPassword;
import com.android.aishangauction.model.member.DataEditPasswordCallback;
import com.android.aishangauction.model.member.SendCodeData;
import com.android.aishangauction.model.member.SendCodeDataCallback;
import com.android.aishangauction.utils.ConstantsUrl;
import com.android.aishangauction.utils.HttpUtils;
import com.android.aishangauction.utils.LoginState;
import com.android.aishangauction.utils.MyLog;
import com.android.aishangauction.utils.ObjectUtils;
import com.android.aishangauction.view.detail.ProvinceBean;
import com.bigkoo.pickerview.OptionsPickerView;
import com.elbbbird.android.socialsdk.SocialSDK;
import com.elbbbird.android.socialsdk.model.SocialShareScene;
import com.elbbbird.android.socialsdk.otto.BusProvider;
import com.elbbbird.android.socialsdk.otto.ShareBusEvent;
import com.sina.weibo.sdk.api.share.BaseResponse;
import com.sina.weibo.sdk.api.share.IWeiboHandler;
import com.sina.weibo.sdk.constant.WBConstants;
import com.squareup.otto.Subscribe;
import com.tencent.connect.common.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

import static com.android.aishangauction.R.id.ll_change_nick;

public class TransparentActivity extends Activity implements IWeiboHandler.Response {

    @BindView(R.id.add_name)
    EditText addName;
    @BindView(R.id.add_phone)
    EditText addPhone;
    @BindView(R.id.add_address)
    TextView addAddress;
    @BindView(R.id.add_detailaddress)
    EditText addDetailaddress;
    @BindView(R.id.add_save)
    TextView addSave;
    @BindView(R.id.add_close)
    ImageView addClose;
    @BindView(R.id.progress_loading)
    FrameLayout progressLoading;
    @BindView(R.id.ll_address_addressedit)
    FrameLayout llAddressAddressedit;
    @BindView(R.id.ll_share)
    LinearLayout llShare;
    @BindView(R.id.ll_update_content)
    EditText llUpdateContent;
    @BindView(R.id.ll_update_img)
    ImageView llUpdateImg;
    @BindView(R.id.ll_update_title)
    TextView llUpdateTitle;
    @BindView(R.id.shuliang)
    TextView shuliang;
    @BindView(R.id.ll_update)
    LinearLayout llUpdate;
    @BindView(ll_change_nick)
    LinearLayout llChangeNick;
    @BindView(R.id.ll_change_edit)
    EditText llChangeEdit;
    @BindView(R.id.ll_sign_phone)
    EditText llSignPhone;
    @BindView(R.id.ll_sign_code)
    EditText llSignCode;
    @BindView(R.id.ll_sign_code_send)
    TextView llSignCodeSend;
    @BindView(R.id.ll_sign)
    LinearLayout llSign;
    @BindView(R.id.ll_change_sex)
    LinearLayout ll_change_sex;
    @BindView(R.id.radioGroup)
    RadioGroup radioGroup;
    @BindView(R.id.radioMale)
    RadioButton radioMale;
    @BindView(R.id.radioFemale)
    RadioButton radioFemale;
    @BindView(R.id.ll_change_pd_old)
    EditText llChangePdOld;
    @BindView(R.id.ll_change_pd_new)
    EditText llChangePdNew;
    @BindView(R.id.ll_change_pd_newagain)
    EditText llChangePdNewagain;
    @BindView(R.id.ll_change_pd)
    LinearLayout llChangePd;
    private String getid;
    private String token;
    private String id;
    private String address1;
    private String address2;
    private String address3;
    private OptionsPickerView pvOptions;
    private String city_id;
    private int number;
    private TransparentActivity mcontext;
    private String team_id;
    private int show_type;
    private TimeCount time;
    private String area;
    private String sexystring="男";
    private int sexy = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.Transparent);//界面半透明
        setContentView(R.layout.activity_city);
        ButterKnife.bind(this);
        mcontext = TransparentActivity.this;
        BusProvider.getInstance().register(mcontext);

        getid = LoginState.getInstance().getid(mcontext);
        token = LoginState.getInstance().getUserInfo(mcontext,2);

        show_type = getIntent().getIntExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_TYPE, 0);

        switch (show_type) {
            case 0:
                llAddressAddressedit.setVisibility(View.VISIBLE);
                ObjectUtils.redAddress(mcontext);
                pvOptions = new OptionsPickerView(mcontext);
                initUI();
                break;
            case 1:
                llShare.setVisibility(View.VISIBLE);
                break;
            case 2:
                team_id = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_TEAMS_ID);
                String team_thumb = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_TEAMS_THUMB);
                String team_title = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_TEAMS_TITLE);
                String team_num = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_TEAMS_NUM);
                ObjectUtils.photo(mcontext, team_thumb, llUpdateImg);
                llUpdateTitle.setText(team_title);
                shuliang.setText("还差" + team_num + "人成团");
                llUpdate.setVisibility(View.VISIBLE);
                break;
            case 3:
                String member_data = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_MEMBER_DATA);
                if (!member_data.equals("")) {
                    llChangeEdit.setText(member_data);
                }
                llChangeNick.setVisibility(View.VISIBLE);
                llChangeEdit.setVisibility(View.VISIBLE);
                break;
            case 4:
                llChangeNick.setVisibility(View.VISIBLE);
                llSign.setVisibility(View.VISIBLE);
                break;
            case 5:
                llChangeNick.setVisibility(View.VISIBLE);
                llChangePd.setVisibility(View.VISIBLE);
                String login_type = LoginState.getInstance().getUserInfo(mcontext, 3);
                if (login_type.equals("0")) {
                    llChangePdOld.setHint("请输入旧密码");
                } else {
                    llChangePdOld.setHint("(旧密码)第三方登录无需输入");
                }
                break;
            case 6:
                llChangeNick.setVisibility(View.VISIBLE);
                ll_change_sex.setVisibility(View.VISIBLE);
                radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup group, int checkedId) {
                        //checkId就是当前选中的RadioButton
                        if(checkedId==radioMale.getId()) {
                            sexystring = "男";
                            sexy = 1;
                        }
                        else
                        {
                            sexystring = "女";
                            sexy = 0;
                        }
                    }
                });
                break;
        }


    }

    @OnClick({R.id.add_address, R.id.add_save, R.id.add_close, R.id.share_wechat, R.id.share_qq, R.id.share_wechatfriends,
            R.id.share_sina, R.id.share_qqzone, R.id.share_copy, R.id.share_canel, R.id.close, R.id.tv_cancel, R.id.tv_yes
            , R.id.ll_change_canel, R.id.ll_change_yes, R.id.ll_sign_code_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.add_address:
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                boolean isOpen = imm.isActive();
                if (isOpen) {
                    imm.hideSoftInputFromWindow(addAddress.getWindowToken(), 0);
                }
                setAddressPop(addAddress);
                break;
            case R.id.add_save:
                String tv_name = addName.getText().toString().trim();
                String tv_phone = addPhone.getText().toString().trim();
                String tv_detail = addDetailaddress.getText().toString().trim();


                if ("".equals(tv_name) || "".equals(tv_phone) || "".equals(tv_detail) || city_id == null) {

                    ObjectUtils.toast(this, "请填入完整信息");

                    return;


                }
                if (!checkPhoneNumber(tv_phone)) {

                    ObjectUtils.toast(this, "请输入正确的手机号");
                    return;
                }
                if (number == 1) {
                    setupdateAddress(tv_name, tv_phone, city_id, tv_detail, id);
                } else {
                    setAddAddress(tv_name, tv_phone, city_id, tv_detail);
                }

                break;


            case R.id.share_wechat:

                Share(1);
                break;
            case R.id.share_qq:
                Share(2);
                break;
            case R.id.share_wechatfriends:
                Share(3);
                break;
            case R.id.share_sina:
                Share(4);
                break;
            case R.id.share_qqzone:
                Share(5);
                break;
            case R.id.share_copy:
                // 得到剪贴板管理器
                ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                cmb.setText("复制此文链接");
                ObjectUtils.toast(mcontext, "地址已复制");
                break;
            case R.id.share_canel:
            case R.id.close:
            case R.id.ll_change_canel:
            case R.id.add_close:
            case R.id.tv_cancel:
                finish();
                break;
            case R.id.ll_change_yes:
                HashMap<String, String> map = new HashMap<>();
                if (show_type == 3) {
                    String nick_update = llChangeEdit.getText().toString().trim();
                    if ("".equals(nick_update)) {
                        ObjectUtils.toast(this, "请输入昵称");
                        return;
                    }
                    map.put("nickname", nick_update);
                    PostDataUpdateMember(map, ConstantsUrl.domain + ConstantsUrl.MEMBERDATA_EDITNICKNAME, nick_update);
                } else if (show_type == 4) {
                    String mobile = llSignPhone.getText().toString().trim();
                    String sms_code = llSignCode.getText().toString().trim();
                    if ("".equals(mobile)) {
                        ObjectUtils.toast(this, "请输入手机号码");
                        return;
                    }
                    if ("".equals(sms_code)) {
                        ObjectUtils.toast(this, "请输入验证码");
                        return;
                    }
                    map.put("mobile", mobile);
                    map.put("sms_code", sms_code);
                    PostDataUpdateMember(map, ConstantsUrl.domain + ConstantsUrl.MEMBERDATA_EDITMOBLE, mobile);
                } else if (show_type == 6)
                {
                    map.put("sex",sexy+"");
                    PostDataUpdateSexy(map, ConstantsUrl.domain + ConstantsUrl.MEMBERDATA_EDITSEXY);
                }

                else {
                    String oldpass = llChangePdOld.getText().toString().trim();
                    String pass1 = llChangePdNew.getText().toString().trim();
                    String pass2 = llChangePdNewagain.getText().toString().trim();
                    if ("".equals(pass1)) {
                        ObjectUtils.toast(this, "请输入新密码");
                        return;
                    }
                    if ("".equals(pass2)) {
                        ObjectUtils.toast(this, "请确认密码");
                        return;
                    }
                    if (!pass1.equals(pass2)) {
                        ObjectUtils.toast(this, "两次密码输入不一致");
                        return;
                    }
                    map.put("oldpass", oldpass);
                    map.put("pass1", pass1);
                    map.put("pass2", pass2);
                    PostDataUpdatePassWord(map, ConstantsUrl.domain + ConstantsUrl.MEMBERDATA_EDITPD);
                }

                break;
            case R.id.tv_yes:
                String content = llUpdateContent.getText().toString().trim();
                PostDataUpdate(team_id, content);
                break;
            case R.id.ll_sign_code_send:
                time = new TimeCount(60000, 1000);
                String sign_phone = llSignPhone.getText().toString().trim();
                if ("".equals(sign_phone)) {
                    ObjectUtils.toast(this, "请输入手机号码");
                    return;
                }
                SendCode(sign_phone);
                break;
        }
    }


    /**
     * 修改地址
     */
    private void initUI() {


        number = getIntent().getIntExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_NUMBER, 2);

        if (number == 1) {


            String name = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_NAME);
            String phone = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_PHONE);
            String city = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_CITY);
            String cityid = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_CITY_ID);
            String address = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_ADDRESS);
            id = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_ID);
            addName.setText(name);
            addPhone.setText(phone);
            addAddress.setText(city);
            addDetailaddress.setText(address);
            city_id = cityid;

        } else {

            addName.setHint("姓名");
            addPhone.setHint("手机号码");
            addAddress.setHint("地区选择");
            addDetailaddress.setHint("请输入具体地址");


        }
    }

    private void setAddressPop(final TextView view) {
        final ArrayList<ProvinceBean> mAddress1 = ObjectUtils.getAddress1();
        final ArrayList<ArrayList<String>> mAddress2 = ObjectUtils.getAddress2();
        final ArrayList<ArrayList<ArrayList<ProvinceBean>>> mAddress3 = ObjectUtils.getAddress3();
        if (mAddress1 == null || mAddress2 == null || mAddress3 == null) {
            return;
        }


        //三级联动效果
        pvOptions.setPicker(mAddress1, mAddress2, mAddress3, true);
        //设置选择的三级单位
//        pwOptions.setLabels("省", "市", "区");
        pvOptions.setTitle("选择城市");
        pvOptions.setCyclic(false, false, false);
        //设置默认选中的三级项目
        //监听确定选择按钮
        pvOptions.setSelectOptions(0, 0, 0);

        pvOptions.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {

            @Override
            public void onOptionsSelect(int options1, int option2, int options3) {

                address1 = mAddress1.get(options1).getPickerViewText();
                address2 = mAddress2.get(options1).get(option2);
                address3 = mAddress3.get(options1).get(option2).get(options3).getPickerViewText();
                city_id = mAddress3.get(options1).get(option2).get(options3).getId();
                MyLog.e("城市id", "城市id" + id);
                view.setText(address1 + " " + address2 + " " + address3);
                area = address1 + " " + address2 + " " + address3;
            }
        });
        pvOptions.show();
    }

    private void setAddAddress(final String tv_name, final String phone, String city, final String useraddress) {

        boolean networkConnected = ObjectUtils.isNetworkConnected(this);
        String address = ConstantsUrl.domain + ConstantsUrl.MEMBERADDRESSADD;
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HashMap<String, String> map = new HashMap<>();
            HashMap<String, String> header = new HashMap<>();
            header.put("UID", getid);
            header.put("TOKEN", token);

            map.put("name", tv_name);
            map.put("zone", city);
            map.put("mobile", phone);
            map.put("address", useraddress);
            MyLog.e("name", tv_name);
            MyLog.e("zone", city);
            MyLog.e("mobile", phone);
            MyLog.e("address", useraddress);
            HttpUtils.post(address, header, map, new dataCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                }

                @Override
                public void onResponse(data response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {

                        ObjectUtils.toast(TransparentActivity.this, "添加成功");
                        Intent data = new Intent();
                        data.putExtra("name",tv_name);
                        data.putExtra("area",area);
                        data.putExtra("mobile",phone);
                        data.putExtra("address",useraddress);
                        setResult(RESULT_OK, data);
                        finish();


                    }

                }
            });
        } else {


            ObjectUtils.toast(this, "网络未连接");
        }
    }

    private void setupdateAddress(String tv_name, String phone, String city, String useraddress, String id) {

        boolean networkConnected = ObjectUtils.isNetworkConnected(this);
        String address = ConstantsUrl.domain + ConstantsUrl.MEMBERADDRESSUPDATE;
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HashMap<String, String> map = new HashMap<>();
            HashMap<String, String> header = new HashMap<>();
            header.put("UID", getid);
            header.put("TOKEN", token);

            map.put("id", id);

            map.put("name", tv_name);
            map.put("zone", city);
            map.put("mobile", phone);
            map.put("address", useraddress);

            HttpUtils.post(address, header, map, new dataCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                }

                @Override
                public void onResponse(data response, int id) {

                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {

                        ObjectUtils.toast(TransparentActivity.this, "修改成功");

                        Intent data = new Intent();
                        setResult(RESULT_OK, data);
                        finish();
                    }

                }
            });
        } else {

            ObjectUtils.toast(this, "网络未连接");
        }
    }

    /**
     * 分享
     */

//    private SocialShareScene scene = new SocialShareScene(0, "演技派", SocialShareScene.SHARE_TYPE_WECHAT, "标题。", "内容。",
//            "http://cdn.v2ex.co/gravatar/becb0d5c59469a34a54156caef738e90?s=73&d=retro", "http://www.v2ex.com/t/238165");
    private SocialShareScene scene;
    public void Share(int type) {

        String title = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_TITLE);
        String content = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_CONTENT);
        String imgurl = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_IMAGEURL);
        String link = getIntent().getStringExtra(ConstantsUrl.INTENT_KEY.MAIN_GROUP_TO_TRANS_SHOW_LINK);

        String appName = getString(R.string.app_name);
        scene = new SocialShareScene(0, appName, SocialShareScene.SHARE_TYPE_WECHAT, title, content, imgurl, link);

        progressLoading.setVisibility(View.VISIBLE);
        switch (type) {
            case 1:
                //微信
                scene.setType(SocialShareScene.SHARE_TYPE_WECHAT);
                SocialSDK.shareToWeChat(mcontext, ConstantsUrl.WX_APPID, scene);
                break;
            case 2:
                //QQ
                scene.setType(SocialShareScene.SHARE_TYPE_QQ);
                SocialSDK.shareToQQ(mcontext, ConstantsUrl.QQ_APPID, scene);
                break;
            case 3:
                //朋友圈
                scene.setType(SocialShareScene.SHARE_TYPE_WECHAT_TIMELINE);
                SocialSDK.shareToWeChatTimeline(mcontext, ConstantsUrl.WX_APPID, scene);
                break;
            case 4:
                //新浪微博
                scene.setType(SocialShareScene.SHARE_TYPE_WEIBO);
                SocialSDK.shareToWeibo(mcontext, ConstantsUrl.SINA_WB_APPKEY, scene);
                break;

            case 5:
                //qq空间
                scene.setType(SocialShareScene.SHARE_TYPE_QZONE);
                SocialSDK.shareToQZone(mcontext, ConstantsUrl.QQ_APPID, scene);
                break;
        }


    }

    @Subscribe
    public void onShareResult(ShareBusEvent event) {
        switch (event.getType()) {
            case ShareBusEvent.TYPE_SUCCESS:
                ObjectUtils.toast(mcontext, "分享成功");
                break;
            case ShareBusEvent.TYPE_FAILURE:
                Exception e = event.getException();
                ObjectUtils.toast(mcontext, "分享失败");
                break;
            case ShareBusEvent.TYPE_CANCEL:
                ObjectUtils.toast(mcontext, "取消分享");
                break;
        }
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (scene.getType() == SocialShareScene.SHARE_TYPE_WEIBO) {
            SocialSDK.shareToWeiboCallback(intent, this);
            finish();
        }
    }

    @Override
    public void onResponse(BaseResponse baseResponse) {
        switch (baseResponse.errCode) {
            case WBConstants.ErrorCode.ERR_OK:
                BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_SUCCESS, scene.getType(), scene.getId()));
                break;
            case WBConstants.ErrorCode.ERR_CANCEL:
                BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_CANCEL, scene.getType()));
                break;
            case WBConstants.ErrorCode.ERR_FAIL:
                BusProvider.getInstance().post(new ShareBusEvent(ShareBusEvent.TYPE_FAILURE, scene.getType(), new Exception("WBConstants.ErrorCode.ERR_FAIL")));
                break;
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == Constants.REQUEST_QZONE_SHARE || requestCode == Constants.REQUEST_QQ_SHARE) {
            SocialSDK.shareToQCallback(requestCode, resultCode, data);
            finish();
        }

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        if(scene==null){
            finish();
            return;
        }
        if (scene.getType() == SocialShareScene.SHARE_TYPE_WECHAT || scene.getType() == SocialShareScene.SHARE_TYPE_WECHAT_TIMELINE) {
            finish();
        }
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, R.anim.pop_down_out);
    }

    @Override
    protected void onDestroy() {
        BusProvider.getInstance().unregister(this);
        super.onDestroy();
    }

    /**
     * 发布广场
     */

    private void PostDataUpdate(String order_id, String square_desc) {


        boolean networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        String address = ConstantsUrl.domain + ConstantsUrl.MAIN_SQUARE_UPDATE;
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            String getid = LoginState.getInstance().getid(mcontext);
            String getpd = LoginState.getInstance().getpd(mcontext);
            HashMap<String, String> header = new HashMap<>();
            header.put("UID", getid);
            header.put("UPSW", getpd);

            HashMap<String, String> map = new HashMap<>();
            map.put("order_id", order_id);
            map.put("square_desc", square_desc);

            HttpUtils.post(address, header, map, new dataCallback() {

                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                    MyLog.e("连接错误", "" + e.toString());
                }

                @Override
                public void onResponse(data response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {
                        ObjectUtils.toast(mcontext, "发布成功");
                        Intent data = new Intent();
                        setResult(RESULT_OK, data);
                        finish();

                    } else {
                        ObjectUtils.toast(mcontext, response.getMsg());
                    }
                }
            });
        } else {

            ObjectUtils.toast(mcontext, "网络未连接");
        }


    }
    /**
     * 修改会员性别填写
     */
    private void PostDataUpdateSexy(HashMap<String, String> map, String address) {
        boolean networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HashMap<String, String> header = ObjectUtils.getHeader(mcontext);
            HttpUtils.post(address, header, map, new dataCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                    MyLog.e("连接错误", "" + e.toString());
                }

                @Override
                public void onResponse(data response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {
                        ObjectUtils.toast(mcontext, "更新成功");
                        Intent data = new Intent();
                        data.putExtra("data_result", sexystring);
                        setResult(RESULT_OK, data);
                        finish();
                    } else {
                        if(response.getCode() == 40001){
                            ObjectUtils.reLogin(mcontext);
                        }
                        ObjectUtils.toast(mcontext, response.getMsg());
                    }
                }
            });
        } else {

            ObjectUtils.toast(mcontext, "网络未连接");
        }

    }
    /**
     * 修改会员资料
     */
    private void PostDataUpdateMember(HashMap<String, String> map, String address, final String nick_update) {
        boolean networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HashMap<String, String> header = ObjectUtils.getHeader(mcontext);
            HttpUtils.post(address, header, map, new dataCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                    MyLog.e("连接错误", "" + e.toString());
                }

                @Override
                public void onResponse(data response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {
                        ObjectUtils.toast(mcontext, "更新成功");
                        Intent data = new Intent();
                        data.putExtra("data_result", nick_update);
                        setResult(RESULT_OK, data);
                        finish();
                    } else {
                        if(response.getCode() == 40001){
                            ObjectUtils.reLogin(mcontext);
                        }
                        ObjectUtils.toast(mcontext, response.getMsg());
                    }
                }
            });
        } else {

            ObjectUtils.toast(mcontext, "网络未连接");
        }

    }

    private void PostDataUpdatePassWord(HashMap<String, String> map, String address) {
        boolean networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        MyLog.e("地址", "" + address);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HashMap<String, String> header = ObjectUtils.getHeader(mcontext);
            HttpUtils.post(address, header, map, new DataEditPasswordCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    progressLoading.setVisibility(View.GONE);
                    MyLog.e("连接错误", "" + e.toString());
                }

                @Override
                public void onResponse(DataEditPassword response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    if (response.getCode() == 0) {
                        UpdataInfo(response.getUPSW());
                        ObjectUtils.toast(mcontext, "更新成功");
                        finish();
                    } else {
                        if(response.getCode() == 40001){
                            ObjectUtils.reLogin(mcontext);
                        }
                        ObjectUtils.toast(mcontext, response.getMsg());
                    }
                }
            });
        } else {

            ObjectUtils.toast(mcontext, "网络未连接");
        }


    }

    private void UpdataInfo(String upsw) {
        SharedPreferences sp = mcontext.getSharedPreferences(ConstantsUrl.USERDATA, 0);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString(ConstantsUrl.USERDATA_UPSW, upsw);
        edit.commit();
    }

    //发送验证码
    private void SendCode(String phone) {
        String address = ConstantsUrl.domain + ConstantsUrl.MEMBERORSENDMESSAGE;
        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", phone);
        map.put("act", "sms_register");
        boolean networkConnected = ObjectUtils.isNetworkConnected(this);
        if (networkConnected) {
            progressLoading.setVisibility(View.VISIBLE);
            HttpUtils.post(address, map, new SendCodeDataCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {

                    progressLoading.setVisibility(View.GONE);
                }

                @Override
                public void onResponse(SendCodeData response, int id) {
                    progressLoading.setVisibility(View.GONE);
                    ObjectUtils.toast(mcontext, response.getMsg());
                    if (response.getCode() == 0) {
                        time.start();
                    }

                }
            });

        } else {

            ObjectUtils.toast(this, "网络连接出错了");
        }

    }

    class TimeCount extends CountDownTimer {
        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            llSignCodeSend.setText("重新获取验证码");
            llSignCodeSend.setTextColor(Color.parseColor("#ffffff"));
            llSignCodeSend.setBackgroundResource(R.drawable.corner_red_bg);
            llSignCodeSend.setClickable(true);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            llSignCodeSend.setClickable(false);// 防止重复点击
            llSignCodeSend.setTextColor(Color.parseColor("#5a5a5a"));
            llSignCodeSend.setBackgroundResource(R.drawable.corner_gray_bg);
            llSignCodeSend.setText("重新发送(" + millisUntilFinished / 1000 + ")秒");
        }

    }

    public boolean checkPhoneNumber(String phoneNumber) {
        Pattern pattern = Pattern.compile("^1[0-9]{10}$");
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }
}
